package com.google.code.easyparking;

import java.io.Console;
import java.io.IOException;

import com.google.code.easyparking.controleur.ControleurParking;
import com.google.code.easyparking.controleur.IControleurParking;
import com.google.code.easyparking.metier.FullParkingException;
import com.google.code.easyparking.metier.IVehicule;
import com.google.code.easyparking.metier.Vehicule;
import com.google.code.easyparking.metier.VehiculeAlreadyInParkingException;

public class Main {

	private static IControleurParking controleurParking;

	public static void main(String[] args) throws NumberFormatException,
			IOException, FullParkingException,
			VehiculeAlreadyInParkingException {
		// TODO Auto-generated method stub
		Console console = System.console();

		System.out.print("Entrer le nom du parking : ");
		String nom = console.readLine();

		System.out.print("Entrer la capacité : ");
		int capa = Integer.valueOf(console.readLine());

		controleurParking = new ControleurParking(nom, capa, 2);

		int commande = -1;

		do {
			System.out
					.println("Taper 1 pour ajouter un vehicule et 2 pour en enlever un");

			commande = 0;

			try {
				commande = Integer.parseInt(console.readLine());
			} catch (NumberFormatException ex) {

			}
			try {

				switch (commande) {
				case 1:
					System.out.println("Attribution de la place"
							+ controleurParking.getParking().getAccesParking(0)
									.getCamera().vehiculeArrive());
					;
					break;
				case 2:
					controleurParking.getParking().getAccesParking(0)
							.getCamera().vehiculeSortie();
					break;

				case 3:
					System.out.println("Affichage des logs");
					controleurParking.getLogEvent();
				}
			} catch (FullParkingException ex) {
				System.err.println("Desolé, parking plein");
			} catch (VehiculeAlreadyInParkingException ex) {
				System.err.println("Vehicule deja present");
			}

			System.out.println("Il y a "
					+ controleurParking.getNbPLacesLibres() + " places libre");

		} while (commande >= 0);

		System.out.println("Nb places : "
				+ controleurParking.getNbPLacesLibres());

		IVehicule vehicule1 = new Vehicule("VOITURE A TOTO", 1, 1.5);
		IVehicule vehicule2 = new Vehicule("VOITURE A TUTU", 1, 1.75);

		controleurParking.getParking().getAccesParking(0).garerVehicule(
				vehicule1);
		controleurParking.getParking().getAccesParking(1).garerVehicule(
				vehicule2);

		controleurParking.getLogEvent();
		controleurParking.getParking().getAccesParking(1).quitterParking(
				vehicule1);
		controleurParking.getLogEvent();
	}
}
